package com.xiangwei.weixin;

import java.util.Date;

public class FormatXmlProcess {
	//文本消息
	public static String formatXmlAnswer(String to, String from, String content){
		StringBuffer sb = new StringBuffer();
		Date date = new Date();
		sb.append("<xml><ToUserName><![CDATA[");  
		sb.append(to);
		sb.append("]]></ToUserName><FromUserName><![CDATA[");
		sb.append(from);
		sb.append("]]></FromUserName><CreateTime>");
		sb.append(date.getTime());
		sb.append("</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[");
		sb.append(content);
		sb.append("]]></Content><FuncFlag>0</FuncFlag></xml>");
		return sb.toString();
	}
	/**
	 * 单图文
	 * 
	 * to 接收方帐号
	 * from 开发者微信号
	 * articleCount 多图文数量,最不能超过10
	 * title 标题
	 * description 图文信息描述
	 * picUrl 图片链接
	 * Url 点击图文跳转链接
	 * 
	 * */
	public String formatXmlAnswerByImgByText(String to,String from,int articleCount,
			String title,String description,String picUrl,String url){
		StringBuffer sb = new StringBuffer();
		Date date = new Date();
		sb.append("<xml><ToUserName><![CDATA[");  
		sb.append(to);
		sb.append("]]></ToUserName><FromUserName><![CDATA[");
		sb.append(from);
		sb.append("]]></FromUserName><CreateTime>");
		sb.append(date.getTime());
		sb.append("<MsgType><![CDATA[news]]></MsgType><ArticleCount>");
		sb.append(articleCount);
		sb.append("</ArticleCount><Articles>");
		sb.append("<item><Title><![CDATA[");
		sb.append(title);
		sb.append("]]></Title><Description><![CDATA[");
		sb.append(description);
		sb.append("]]></Description><PicUrl><![");
		sb.append(picUrl);
		sb.append("]]></PicUrl><Url><![");
		sb.append(url);
		sb.append("]]></Url></item>");
		sb.append("</Articles></xml> ");
		return sb.toString();
		
	}
}
